﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_PERMISSION.Base;
using ERP_RORZE_PRODUCT.Product.DAO;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.Base;

namespace ERP_RORZE_PRODUCT.Product.XLBM
{
    public partial class ctrlXLBM : DevExpress.XtraEditors.XtraUserControl
    {
        ClsXLBM clsXLBMDAO = new ClsXLBM();
        DataTable dt;
        DulieuANO b = new DulieuANO();
        private LogUtils log;
        
        public ctrlXLBM()
        {
            InitializeComponent();
            log = new LogUtils();
        }
        void Reload(object sender, EventArgs e)
        {
            dt = clsXLBMDAO.GetAllDataANO();
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void ctrlXLBM_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            b.ID = int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"ID").ToString());
            clsXLBMDAO.DeleteDataANO(b);

            //write Log
            log.Table = LogConstant.Table.Product.XLBM;
            log.Task = LogConstant.Task.Delete;
            log.Description = "Date: " + gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Date") + "; OrderNo: " +
                              gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "OrderNo") + "; PartNo: " + gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "PartNo");
                       
            log.WriteLog();

            Reload(sender, e);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            btDelete_Click(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            frm_DataANOAdd frmAdd = new frm_DataANOAdd();
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.Show();
            Cursor.Current = Cursors.Default;

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            btnAddNew_Click(sender, e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            frm_DataANOEdit frmEdit = new frm_DataANOEdit();
            frmEdit.ID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString();
            frmEdit.Reload += new EventHandler(Reload);
            frmEdit.Show();
            Cursor.Current = Cursors.Default;

        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            clsConstantsFuction.ExportToExcel(gridView1, 1, true);
        }

        private void btnImport_Click(object sender, EventArgs e)
        {

        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            btEdit_Click(sender, e);
        }
    }
}
